bug fix in readfile function