Rewritten login method to be faster