Handle location not found and other code improvements.