moving error handling to query.js