refactoring checkout() method