replaced ternary operator with && and || operations