fix memory exception bug