Platy i am test your Cleave again please look images:
1) Before pillage
2) First pillage (Plantation removed - North East from swordsman)
3) Second pillage (ERROR)
4) Third pillage (Farm removed - North from swordsman)
5) Fourth pillage (ERROR)
This 100% works if i have all improvements around me, but if i haven't improvements around and i am pillage, when your code activate they look that on surrounding tiles has not improvement and program show error, this is my opinion.
I want to ask you something, has nothing to do with Civilization. Which program language you know? I know only C for now. In the coming year i will plan to learn java, C++ and C#.