Wrap indexdict into a function and do all the rest