remove background events on close to prevent memory leaks