Refactor distance.c and update input file