Fixed code causing index out of bound exception in QueryData API