Merge with Choi's working login function