fixing some bugs from the memory leak fix