refactor python script