removed inputVal, using dynamic programming to set value