**Changed realloc to add memory correctly**. Old code won't work for larger arrays