Replaced __dict__ assignment with setattr