Add unit tests. Minor fixes.