This is what I *should* have done back then; thanks to Jeff Mitchell for pointing out a problem with the old method. The old one is *definitely* a kludge. <shamefaced grin>
...after getting rid of most of the hardcoding (though not all!)