Refactoring done on controller and form validation added