Refactor codes in worker