Fixed invalid index bug that caused next() method to fail