couldn't this all be replaced with "next = next % panelCount"?