update fix inefficiency design of the function