Add unit tests, fix compile