Fix compilation problems and memory issues.