bytes written incorrect (but no users of this AFAIK), also don't call write if there is nothing to be written