Even after applying the various recommended fixes in the comments the Flexible Solution would still break for me in certain cases, so after getting it working I decided to just add my version to the main Wiki page. This should save other folks the trouble...