Fixed query() function to only return a single row at a time