finished the rewrite
updated tests