Moved the code to the model