fix dereferencing the end iterator in case we get an empty result array