massive rewrite, mostly just reformating