Refactor some templating stuff and add set_fq functions.