preallocate and upsert methods and tests improved