Replacing iterative str lookup with set lookup