almost finished rewriting