fixed issue with formatting query