Refactoring of login code
Added log out functionality