initial triple-key helper function
a little reorganizing and renaming for clarity