updated for rate-safe counting and bunch fitting