Doesn't buf need to be declared outside the "if" block for this to work?