A number of fixes and optimizations.