Try to avoid two nested ternaries.
Also, there are some cs errors in there.