Made the code a little more defensive when handling upstream writes.