Add some sys.stdout.flush + remove unused variable