fix file reading and some allocation error