Refactoring the solution by introducing a guard clase