Correctly add the close listener