Using set instead of array for faster membership lookup