Lots of code cleanup for controllers