replace seq hackery with a while loop