fixed mem leak
some changes