fixed bugs in reading