Updated to keep track of whether or not there were events queued before closing and freeing a structure