modified to deal with nonexistent paths