Changed the saved index according to buffer size.