Replaced List<T> by HashSet<T> where possible for performance improvements