Also cleanup the underlying code (cherry picked from commit 4f06c1cc09d15245b26b8a862738cb6a859fedcc)