renamed buf to buffer