fixed a bug where the output was being written to console instead of stdout