fixed up the memory management issues. looks like all that's needed now is to fix up the unserialize