Fix tests, cache parent_child, refactor