optimize the add logic