replaced long buffer operations by functions