fully functional implementation