substantial rework of query
add config variables and library loads