refactor function generators to make route more generic