improved implementation not using TreeSet, and some initial work on integration testing of cookie handling