Added lots of input validation.