Added phpunit config.
Added more and better unit tests - most classes have 100% coverage.
As a result, fixed some dumb bugs.