A lot of smart fixes
Library tweaks
Fixed for memory leaks and deallocation problems