refactor to add is_valid_substitute