Improving function performance