Tests and algorithm of deallocation.
Still some bugs to fix. (see test case)