Unit tests, fixes