created correspondence generation function and separated support routines out into a shared library