clean up, some refactorings dealing with buffer size of buffer