Some patches from upstream; to be committed.