Added performance speedup in finding ancestors. Added some utility classes.