modify the code to keep orignal function work well