generalized the templates and fixed display bug in index function