extract controller logic to model