Fixing more potential infinite loops in write