Improved tests. Lots of fixed bugs.