refactored out rewriting and adopted core.match