changed locked to use prealloc