TreeStructureException: Attempted node removal not allowed - Error for IfNode

Hi,
my URCap code removes child nodes below the Cap root. It works for most nodes but I get the following error for an IfNode:
com.ur.urcap.api.domain.program.structure.TreeStructureException: Attempted node removal not allowed.

Any idea why the IfNode throws the error and how to fix it?