re-rolling #217 against 9.0.x branch.