Made some serious performance optimizations.