Recoded queue limiting logic from scratch.