Fix bug with reallocation