Refactor method to make logic clearer.