Fix bugs where the light index wasn't ordered right and add a stacking pattern