added try catch for query parsing