added checking for distance between new and old location. refactor