Fixed off by one issue in buffer