minor fixes, optimizations