refractored index controller into more manageable pieces