Updated worker script with better error logging