Fix 'make test' and add unit tests