redid the profit calculating function, as explained in the pdf