I'm not sure why it triggers there, it shouldn't do so unless it is greater or equal to 3 .. err .. maybe remove the extra set of brackets around the key?
Code:
    if ( $msgtags(msg-param-months).key >= 3 ) {

..and replace line 3 with that?

But it is correct that it should give a 400 as a value if it goes through at 2.