moved some code around to fix login bug