Memory issues fixes