Implementing clock sweep algorithm.