refactoring run method into smaller methods