optimize the codes