fixed logic error in buffer