making ternary conditional statement more robust