added some nice automated function for finding modes. added some stuff to template