changed realoc to malloc