Small fixes and optimizations