Fix bugs where we didn't check for null on main window before refresh