add function optimization