Rewriting texture code, fixed current memory leaks.