Fixed memory leak
Added memory leak tests