Moved from controller to model