Cleanup refactoring in main