added a functional version