Add button and fix memory leaks