added rewritting framework