Some basic error handling and query validation