Bugfix: Account for rules sorted after unmanaged rules

The offset calculation assumed unmanaged rules are numbered 9000+ and would be sorted to the end and didn't need to be accounted for. This caused failures when people used9-numbered rules. This should fix that.

Additionally, for rules that are 9-numbered, they should be ordered *after* unmanaged rules, so this fixes that too.

So when encountering unmanaged rules, the order will be something like this:

- Managed rules that begin with 0 through 8
- Unmanaged rules (which are assigned 9-numbers)
- Managed rules that begin with 9 (but not numbered lower than the unmanaged rules)

Mixing unmanaged rules with managed rules is still not officially supported, but at least we can try and behave with them.