refactor: Move key-value related funcs to key_value.c