minor fix, and optimizations.