Improvements to handling of collections.

The collection handling code now uses shared memory
and improved parallelism, which results in a substantial
speed-up.