Use buffer instead of string slicing to reduce memory usage.