making some subtle optimizations