simplify dp algorithm / remove redundant code