editted malloc() and read/write parameters