Improved error handling and data storage/retrieval.
More concise logging directive.
Make use of deferreds for cleaner label prefetching; store result based on key and gid (instead of globally); function cleanup.