Pass by reference the buffer to read

Also added the NullPointer Exception