Implemented boundary checking for the Buffer implementation.