sort start and end