fix bugs (change distance r type from int to double)