tidying up. Added some patterns to match with fillings and shapes.
Algorithm P' works. The paper had a typo... 0 should be i0 in the conditional branch. Verified output is as expected.