Added optional pyformat named parameters for queries
Corrected bug with IF logic which caused a second exception once the first was detected