r778: reduced the number of alloc() calls a bit