Started working on a function to consolidate the logic that's duplicated in setting up commands and queries