Modify bufferHandler() and added test code for DelayedWrite