Cost calculation function update!