Move generic code into index