buf_comparison: split the code up and move it around