Trying to fix problem with calculateCost