Use atomics for counters.
Use 'const' where possible in extractor and simplify iterator loop.
Merge pull request #1312 from joto/const

Some cleanups in the extractor code.