Replace untilTerminate with whileM