Minor speed and stability optimizations