realloc optimization working