roughly split the main code out into a library