Fixed some bugs and added validations