Optimize difference and parentWays