WIP Many memory leaks plugged and bugfixes