moving code to the model