Improvements to the query page
Correctly locate the end of the statement.  Fixes #1