More compacting of code, and added first set of unit tests.