fixed memory errors