Some test units added, and some refactoring made