implemented writeIndex