edits to distance classes
Fixed infinite loop, separated special cases