Fixing bug in figuring out parents