DP: take care of edge cases