Refactor first method to use ternary operator