PC 15: ugly but working

pinned down the logic behind problem 15, now to just make it not a mess.