Optimizations on several functions