minor changes to var names, and correctly calculate base case of U matrix