big refactoring to support limits and rates headers