Python3 compatibility improvements