Refactor set_xattr instead of duplicating the code.