Minimal change.
Added consistency check for all variables that come from user input. Tested.