parameter sanitization
fixed template generation for distances