add and test query formatting code