fix flake8 violations
fix built-in function mismatch between 2 to 3
update codes to python 3 compatible