Cost compute fix

A clean branch with just the cost computation fixes..