Refactor code and fix bugs with cart actions