added function to read the entire buffer