Move some code from Application to corresponding controller