Added more error checking.  It now doesn't crash when you press the red X