added the cleanup mechanism