Optimization : Use of HashSets instead of lists when possible