Added duplication checks

Duplication & Refactoring of tree processing