Fixed GL memory leaks.
Minor refactors and optimizations.