Change code to use HashSet instead of ArrayList