Python 3 compatibility improvements