Refactored worker code & Fixed error propagation