update to use engine.write callback