code polish,fix memory leaks,coding style