Finishing up the memory allocation algorithm