Fix type confusion issues in Python 2.