Improved buffer and file output