Mem leak & useless code remove