Updated: change q to q=p+size+1 and printing the contents of the buffer