Implemented findPath function