made a few minor optimizations.