Fixed bugs in cost computation