added a context closed event listener to help prevent memory leakage