Move out rules related funcs from key_value.c to rules.c