Fix initialization sequence to prevent freeing of unitialized objects.