Moved logic from view into routes