close listener correctly