Add some minor improvement of performance

* use HashSet instead of TreeSet
* use String.startsWith instead of String.contains
* use one NOT test instead of two OR tests