minor cleanup + fixed memory leak