refactored to make it closer to M/R style