Improved the test coverage, found two more bugs.