Refactor remove duplicated code and use is_not_set