Improved template cart code