sorted out rewrite engine