Implement new logic using of new method that get cost dimension
Bug fix avoid  NPE