complete functional implementation and add test case