Fix issue #8819 and #9771