refactored code in user model