Replacing print commands with calls to a stream write().