rewrite much of it