Fixes #9724 Could be cleaned more though. (cherry picked from commit c7f0a54a375380a8b6bd100c712acb2e01c11ac3)