Fixing bug with read index being reset