Define controller functions in closure