Changed HashSets to LinkedHashSets to preserve insertion order