Bug corrections and optimizations.