This is adapted from SDNQ from the SD.Next project: https://github.com/vladmandic/sdnext/tree/master/modules/sdnq