Refactor to better handle errors.
We do not want garbage-in-garbage-out problem getting spread out.So all of the function have rigid assumption about
their input unless the input means to be dynamic and flexible in which case return type will not be void.
Make Validate return value to boolean instead of int.