Improve determining buffer size