Modified code to utilize ternary operator to simplify layout of the code.