Refactor code to user model