Changed location where check_valid_shell happens