Migrating to using the cleanup function