added a check that forces the posterior edge to be at the end of the path