refactored login, added error_log