loop detection and pathway sorting