Charles: refactored the code and improved the python execute script.