delete some unnecessary code and a memory leak