Memory problem fixes