Add unit tests and fix code to get a clean build