Added extend merging
Fixed circular detection