Heavily refactored pattern matching to make better use of phractal's capabilities.