Code clean up seccond commit
Code clean up and fixed memory leack third commit