Fixed small memory leaks. Added functions to clear most part of data