refactor for equal length array switch