Bug fix: output stream was not closed properly