Non crashing version, still have to work on aternate cost computation