Refactor assign_attributes