modify the code to improve the performance