Refactored code so that the execution code is simpler