moved controller logic to model