ring: move code in a new header file