Refactored the first function in user.js