The mat->quantity() method call is used twice here. It's possible that we (I) coded this inefficiently. In general, if we're getting a double out of one of our method calls, I think the double should just be stored at scope.