Wow, that was much more difficult than anticipated. Finished debugging problem #4. It doesn't look pretty, but it works.