Perhaps this should be a set so that it isn't an O(n) membership check below.  See, for example, http://stackoverflow.com/a/480227