this generalizes the function to work with buffersize set