If anyone is interested, I just implemented this more or less properly in my branch and it seems to work as far as I can tell. Maybe @steve or @gbadner would like to pick up this issue again and apply a similar fix to the main branch?