refactored for support python2.7