fixed some mem errors