fixing error on empty array for closest