using tenary operator to reduce code complexity