Optmized the function.