Refactored again cost computation.