fixed the realloc bug for good this time