Added checks and changes for invalid or impossible paths