Optimize tests and scripts