more refinement ... now the code passes the unit tests