Great refactoring for a more straightforward logic