optimize the rank