Moved the ref function from mongoose to a separate helper