basic working version of value-iteration