written as library with test cases