Clean up code in main controller