Refactory the light iteration code and add the test files as well.