pseudocode for buffer logic (oops on the first commit)