added condition to check if the path exists