Refactor autologin