Bug fixes and optimizations.