refactored to use write_attribute