working encoded value iteration