Moved logic from stocks controller to model