Unit tests, some minor fixes