Integrate scratchpad client handling more deeply.

Especially unmapping the scratchpad is quite delicate, but it seems to
be quite stable.