Handle closing buffers more elegantly