Improved buildParentsFilter(). Now it works for parents from different contexts