fix memory leak; some minor cleanup