Fixing errors for patch in 8.1.x branch.
Interdiff taken from #27 patch.