Refactored much of the execute() method into separate classes.