refactors some controller code