Significant performance improvement of  function.