RMG cleanup, bugfix, and test refactoring