Readded a cleanup function that got lost in a code merge.