Creating a new function for finding the path so to solve #1