solved the problem using a buffer for the output as well