Refactored code
Fixed wrong condition in ternary operator