add writeAndWait functionality