bug fixes - minor optimizations.