various linker fixes, memory deallocation and some transient MEM_DEBUG stuff
somewhat working example