refactor login, small fixes