a few optimizations/fixes