Setup for logging in. Bugfixes and clean up to remove database hits