python 3 compatibility changes (working in both python 3 and 2.7)