Fixed unit tests and other improvements