add error handling and fix log-in