refactored save_result() out of handle_buf()