major rewrite to fix bugs for pending and failing tests, lots of code cleanups, remove diff