Changed memory storage to a circular buffer

nit: Why not `ret[i] = &e`?