unify monitor cleanup code