added better error handling for login
fixed a login bug