refactor to improve the code used for creating the users