Properly close output buffers to fix #107