Small bug fixes, optimizations.