Yeah, this should really be refactored out of the servlet. I have a few pretty good ideas about how to implement this cleanly, so maybe I'll work on that over the weekend.