refined to extract the endpoints