Fixed the stack overflow with an Writer wrapper