pre-process distance measure