Use sets for doing repeated lookups faster