proposed solution - passes regression testing, at least
test code doesn't seem to work...