Little refactoring. Add autologin and logout