added login and logout, also a little bit refactoring