Some bug fix to improve python3 compatibility

do you know what version this was introduced in?