apply earlier fixes to second control flow

Thanks for your quick response to, and acceptance of my earlier pull requests.

I must admit that the changes were hastily written while working on a prototype. Today I noticed that there is a second control flow to which #1 and #2 apply.

Please accept this patch to fix the same issues in the second control flow.