revised functionality to do location detection correctly