Extract the functions in their own package

Add test cases