Messages and closing

Improve close window handling.