Original diff from Tom Murphy, thanks! Some hints from sdk@ and bentley@, tweaks by me. OK sdk@ and bentley@ (maintainer)