Imrpove rainbow algorithm