Added query validation functions, fleshed out tests