Now using the new re package for pattern matching. Greatly simplified the source.