while is working but needs refinement