added ternary and user input validation