Can we maintain a mapping, rather than this O(N) lookup?