functional implementation