I added my crappy code.  Feel free to make it not work any more.  The functions are not yet set in stone.