refactor the model function