Fixed off-by-one error in query_all