implented takeWhile