added more detail to error message
factored out render of query results into function