make faster version function

Original function is too slow.
new one is much faster than old function.