refactoring code and full functionality for user model