Fix reallocation algorithm