quite a bit of rewriting