add self-loop detection in case and if statements