refactored some code and add python3 support.