clean code and soft migrate to python3
merge
python2 compatible