remove memory leak and modify State structure