cart code refactor