removed nonsense and added a distance measure