Some bug fix to improve python3 compatibility