Value iteration works, but is ugly