fixed the code after the optimization