rcmd algorithm