rewrite a lot of stuff