fixed distance function, added comments, and put core distance matrix generation function into scipy C routines.