added user login and refactored