Refactored cart code.