Added logic to ensure the buffer doesnt get too big which would cause problems