Fix using offset and limit where limit goes beyond array bounds