implementing rate-safe counting ideas