Fix errors introduced in previous commit
Refactor buffer; highlight potential deadlock