factor out r* implementations in their own file