Fixed some of the issues with realloc