Logout action + fixes and refactoring