unregister when closing window + test code