added logic to only show message if key is not valid