Rewrite a bunch of code
minor test changes