Requested by Marcus Merighi, patch by Ian McWilliam (MAINTAINER), input from sthen@ and tweaks by me. ok sthen@