Unit testing and minor refinements