Used ternary operator instead of before and after if checks.