improve mutex
remove memory leaks