adding first version of dynamic programming functionality