refactored login, added form validation