rewrite

complete rewriting