fixed memory leak and removed unnecessary static variable