Rewritten evolve-grid in a functional style