Change takeWhileM implementation