adding logging functionality, and fixing bugs that could lead to memory leaks and such