Fixed the getDistances function. Made it slightly prettier