best version yet lots of debugging has happened and the function does give output that is corrrect. minor revisions needed for path_finder