remove duplicates and inverted dependencies