adding some memory management code
improving memory managemnet
after some hacking, memory is working