Combine identical logic in near()