Better implementation of gh-693.