Move logic from view layer to routes