refactor take-while