bug fix & fix memory leak