Added some validations, fixed some bugs.