Tweaks to make things work in both python 3 and python 2