reduce compiler warnings and fix memory leaks