refactored orginal sciprt

python 3 support

respect pep8 coding style