wip-442: Token aware writes

This is a very nice piece of general-purpose functionality. Why hide it here and not move it to util?