fixing realloc error