merge request loop logic in rm func