minor fixes and optimizations