Cost function updated to fix external indices mapping