Fixed bugs with the getNearest function. Added a function to determine where to store data.