Made path adding more robust