Move processing code from view into controller