Clean up main and move the code to __main__.py
Review 1
Fix some TODOs.