refactoring to extract main and create a library