Minor bug fixes. Unit tests added.