Refactor checkout code