Added some extra optimizations.