Rewritten worker algorithm