adding unit tests and minor fixes.