adding login form and refactoring code