fix to work in both python 2 and 3