TimedQueue and some refactoring