move the API wrapper code into a separate module
refactor so module can be used by other programs