move close modal listener outside of modal() function definition