use stack for parent references to favour immutabiliity