Move sorting from view into controller