Fixing extract script with some process counting magic