fix distance, add logging