pseudocode for buffer logic