made path modification more robust