added ternary and defined function