Fixes and optimizations.