Fixes bug in coordinate distance function.