refactor existing python code to include main() routine