Changed buffer to buf