Small refactors, Unit test covers more cases.