adding some guard code so if dismissing happens (e.g. in a cleanup hook) we don't try to remove an observer we never added.