smaller fixes and optimizations