minor code clean up to reduce duplication
Updated unit test