Improve write_attributes and return attributes as hash with indifferent access.