Added error handling to login