Far from ideal, but works.
Suggestions welcome.