Fixed memory leak and huge performance improvment