Backported this branch for Python2