fixed a bug where on close messages weren't being sent properly