refactor decode_buffer to remove unnecessary code