fixed some varnames. fixed some memleaks