fix memory leak, fix some assertions