refactored if/else, added authentication in user model