implemented event loop in writer. big performance issue