Optimized getnext