addressed issues in pull request
python code refactoring