Fix the broken __main__ and remove some pyflakes errors