rewritten sequentialize in a functional manner