Added bound checks for queries.