Refactored code with IntelliJ