wouldn't this be simpler?
 ~~~~
parentWasClosed = !parentWasOpen
~~~~