Update to v6

Upgraded to v6. Lots of things were fixed. Complete rewrite.