add account class and fix memory leaks