begin refactoring into master and worker