modified read function, it is almost done!