optimizations; small fixes