doing some dynamic programming and shiiit