Nearly went insane trying to fix some bug to do with realloc() copying
memory to a different location. Learnt something new today.