I added some checks, and it seems to run better now
Created dually linked list of allocations. Each allocation has timestamp & status. (Allocation is automatically freed, if it isn't being used in 10minutes.. which prevents io from hogging resources, when script crashes)