More locking; proper memory allocation.