Fixes some issues and extends unit tests.