Fix mem problems