Minor refactoring and cleanup
Introduce ref_buffer() helpers