Bugfixes, refactoring, login logic