restructured to use controllers instead of anonymous functions