Optimization of some functions.