replaced takeWhile/dropWhile with span