fixed memory bugs
fixed some bugs