almost finish rewritting