Initial diff from Mikko Tolmunen. Thank you! Some corrections from brad@. Tested by deanna@, naddy@, brad@ and myself. ok deanna@, brad@