Add Python2 compatibility and fix some bugs