fixed some small memleaks, small optimalizations