generalized maincontroller
cleaned up code