Python2 compatibility fixes