Fix memory leak, compiler warnings