More tests, bug fixes and reorganization.