refactored the code to put it in a dynamic library