fixed the mem leak finally