changes to work with type="both", factors and grid