Made path check in while loop more general to account for Ubuntu's weirdness.