Unit tests and other improvements