added better error handling for login