OK. This version works. Need to stress test it a little, and to set the extension up so that it
creates the custom data group (if it doesn't exist,etc). Also need to potentiolly handle MAX query returning nothing.