Redesigned some rate limiting code