Expanding out the cleanup function