refactor code improve performace