better function for memorypool