Fix null reference exception when closing window refs #1