reorganize code into a library