refactoring of the user and error handling