modify the algorithm for add/remove time