Fixed bug in memory pool management