Refactored the code to work with users