Off by one error in realloc. Initialising counter to 1 now.