refactored to clean up main controller more