Refactored method to use a ternary operator