Moved business logic from view to controller