Define controller function