Fixing memory issues and memory leaks, especially with the raw photo data