Updated comments and reordered calculations.