Added form closing event to write before components are destructed