do some refactor in initCart, add a parameter to let this function easy to test