Added cycle detection in pattern definitions