Fixed several bugs when reading data