Python 3 compatiblity fixes