Refactor worker#run to prepare fix for #222

Break up `worker#run` into smaller methods and give each a meaningful name so it's easier to figure out what it's doing and allow code reuse.

Collapse duplicate `if-else` constructs.