added writing binary output