Top level worker code.