added sequence rewriter and some tests.