Move controller logic to model