small fixes and optimizations