first attempt at complete memory manager, not tested