Move logic from view to model