Fixed bugs in buffer class.