add method to check if buffer is valid