refactor on_attr