Python 3 fixes
Merge commit 'dac142f8b72bca4c1767699813f5847f27ff2f56'.