replaced if-else block with ternary operator