move some controller logic out of views