Rearrange path logic