Remove reference to non-existing variable
Move handling of query results to a separate class