optimize the loop on registering