partially python 3 compatible