Revamp login logic. Fixes #150