Code cleanup and better location accuracy code