move some controller logic to models